package cn.dzhang.rcp.hyperbola;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.model.IWorkbenchAdapter;

import cn.dzhang.rcp.hyperbola.common.UIUtils;

public class HyperbolaContentProvider implements ITreeContentProvider {

	@Override
	public void dispose() {

	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

	}

	@Override
	public Object[] getElements(Object inputElement) {
		return getChildren(inputElement);
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		IWorkbenchAdapter adapter = UIUtils.getAdapter(parentElement);
		return adapter != null ? adapter.getChildren(parentElement)
				: new Object[0];
	}

	@Override
	public Object getParent(Object element) {
		IWorkbenchAdapter adapter = UIUtils.getAdapter(element);
		return adapter != null ? adapter.getParent(element) : new Object[0];
	}

	@Override
	public boolean hasChildren(Object element) {
		return getChildren(element).length > 0;
	}

}
